﻿/*-------------------------------------------------------------------------
* 命名空间: WaferSelectV3.Common/ProcessHelper
* 类       名: ProcessHelper
* 功      能:  TD
* 时      间:  2024-05-27 11:53:26
* 版      本:  V1.0
* 作      者:  Fioman
* 格      言:  Talk is cheap,show me the code ^_^
*-------------------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WaferSelectV3.Extensions;

namespace WaferSelectV3.Common
{
    public class ProcessHelper
    {
        /// <summary>
        /// 关闭已经打开的Excel文件的进程,如果一个Excel文件已经通过Excel打开
        /// </summary>
        /// <param name="filePath"></param>
        public static void CloseOpenedExcelFileProcess(string filePath)
        {

            try
            {
                Process[] processes = Process.GetProcesses(); // 获取所有的进程
                foreach (Process process in processes)
                {
                    string processName = process.ProcessName.ToLower();
                    if (processName.Contains("wps") || processName.Contains("office"))
                    {
                        process.Kill();
                        process.WaitForExit();
                    }
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.WriteLogMain(ex.GetFullException(), LogType.Fatal);
            }
        }
    }
}
